<?php
// File Security Check
if ( ! empty( $_SERVER['SCRIPT_FILENAME'] ) && basename( __FILE__ ) == basename( $_SERVER['SCRIPT_FILENAME'] ) ) :
	die ( 'You do not have sufficient permissions to access this page!' );
endif;

/* Template Name: Services - Two Columns */

get_header(); ?>

<?php get_template_part( 'page-title' ); ?>

<!-- BEGIN #container -->
<div id="container" class="clearfix">

<?php if ( have_posts() ) : ?>

	<?php while ( have_posts() ) : the_post(); ?>

		<!-- BEGIN #content -->
		<section class="col-full clearfix service <?php echo $post->post_name; ?>">

			<div class="entry">
				<?php the_content( __( 'Continue reading', 'nicethemes' ) . ' &raquo;' ); ?>
			</div>

			<?php $args = ( array(
									'taxonomy'		=> 'service-category',
									'hide_empty'	=> 1
							));
			$categories = get_categories( $args );

			if ( ! empty( $categories ) ) : ?>

                        <div class="filter-area">
                            <h4 class="service-filter-title"><?php _e( 'Services:', 'nicethemes' ); ?></h4>
                            <!-- BEGIN #filter -->
                            <ul id="filter">

                                            <li class="active"><a data-value="all" href="#"><?php _e( 'All', 'nicethemes' ); ?></a></a></li>
                                            <?php  wp_list_categories( array(
                                                                            'title_li'			=> '',
                                                                            'show_option_none'	=> '',
                                                                            'taxonomy'			=> 'service-category',
                                                                            'hide_empty'		=> 1,
                                                                            'walker'			=> new Nice_Walker()
                                                                            )
                                                            ); ?>

                            <!-- END #filter -->
                            </ul>
                        </div>
                        
                        <div class="service-description">
                            <?php 
                                //$categories = get_terms( 'service-category', 'orderby=count&hide_empty=0' );
                                $terms = get_terms("service-category");
                                if ( !empty( $terms ) && !is_wp_error( $terms ) ){
                                    foreach ( $terms as $term ) {
                                        $tid = $term->term_id;
                                        echo '<div class="description" id="description-term-'.$tid.'" style="display:none;">';
                                        $tdesc = get_terms_meta($tid, 'service-category-long-description');
                                        print($tdesc[0]); 
                                        echo '</div>';
                                    }
                                }
                            ?>
			</div>
                        
			<?php
			endif;

			$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
			$temp_query = $wp_query;

			$args = array(
							'post_type'		 => 'service',
							'posts_per_page' => -1,
							'no_found_rows'	 => true,
							'paged'			 => $paged,
							'orderby'		 => 'menu_order',
							'order'			 => 'ASC'
						);

			query_posts( $args );

			if ( have_posts() ) :

				$loop = 0;
				$columns = 2; ?>

				<ul id="services" class="two-col-grid grid service-grid-two-col clearfix">

				<?php while ( have_posts() ) :
						the_post();
						$loop++;

						$terms = get_the_terms( get_the_ID(), 'service-category' ); ?>
					<li data-id="id-<?php echo $loop; ?>" class="<?php if ( $terms ) : foreach ( $terms as $term ) : echo 'term-' . $term->term_id . ' '; endforeach; endif; ?> <?php if ( $loop % $columns == 0) echo 'last'; if ( ( $loop - 1 ) % $columns == 0 ) echo 'first'; ?> clearfix">
					<div class="boxgrid caption">

						<?php if ( has_post_thumbnail() ) : ?>
						<div class="thumb view view-more">
									<a href="<?php the_permalink(); ?>" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title() ); ?>">
										<?php nice_image( array( 'key'	=> 'service-image', 'width'  => 480, 'height' => 180 ) ) ; ?>
										<div class="mask"></div>
									</a>
						</div>
					<?php endif; ?>

					 <span class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title()); ?>"> <?php the_title(); ?></a></span>

					 </div>
							<div class="service-excerpt">
							  <div class="excerpt-content">
									<?php nice_excerpt( 170 ); ?>
							  </div>
                                                            <a class="readmore" href="<?php echo get_permalink( get_the_ID() ); ?>" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title() ); ?>"> <?php _e( 'Read More', 'nicethemes' ); ?></a>
							</div>
				  	</li>

			  	<?php endwhile;?>

				</ul>

			<?php endif; ?>
			<?php wp_reset_query(); ?>

			<?php $wp_query = clone $temp_query; ?>

		<?php endwhile; ?>

		</section>
		<!-- END #content -->

<?php else : ?>
		<header>
			<h2><?php _e( 'Not Found', 'nicethemes' ); ?></h2>
		</header>
		<p><?php _e( 'Sorry, but you are looking for something that isn\'t here.', 'nicethemes' ); ?></p>
		<?php get_search_form(); ?>

<?php endif; ?>

<!-- END #container -->
</div>

<?php get_footer(); ?>